package com.zhoust.fastdome.filter;

import com.zhoust.fastdome.common.CommonConstant;
import com.zhoust.fastdome.utils.MyRequestUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

/**
 * @author zhoust
 * @Date 2021/9/28 16:56
 * @Desc <TODO DESC>
 */
@Component
@Slf4j
public class MyFilter implements Filter {

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        log.info(">>>>>>>>>>过滤器出生<<<<<<<<<<<<");
        Filter.super.init(filterConfig);
    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        log.info(">>>>>>>>>>开始奋斗的过滤器<<<<<<<<<<<<");
        // 更改request,便于读取Body中的值
        MyRequestUtils myRequestUtils = new MyRequestUtils((HttpServletRequest) request);
        chain.doFilter(myRequestUtils,response);

        log.info(">>>>>>>>>>奋斗完成的过滤器<<<<<<<<<<<<");
    }

    @Override
    public void destroy() {
        log.info(">>>>>>>>>>过滤器度过光荣的一生<<<<<<<<<<<<");
        Filter.super.destroy();
    }
}
